#include<stdio.h>
#include<unistd.h>

int gret = 100;

int main(){
  pid_t id = fork();
  if(id < 0){
    printf("fork error\n");
    return 1;
  }else if(id == 0){

    int cnt = 0;
    while(1){
    printf("我是子进程，pid:%d,ppid:%d,gret:%d,&gret:%p\n",getpid(),getppid(),gret,&gret);
    sleep(2);
    cnt++;
    if(cnt == 5){
      gret = 300;
      printf("子进程的全局变量已经更变\n");
    }
    }

  }else{
    while(1){
    printf("我是父进程，pid:%d,ppid:%d,gret:%d,&gret:%p\n",getpid(),getppid(),gret,&gret);
    sleep(1);
    }
  }
return 0;

}
